var app = getApp();
Component({
    properties: {
        productList: {
            type:Array,
            value:[],
            observer:function(newVal, oldVal){
                if(!oldVal[0])return;
                for(var i = 0;i<oldVal.length;i++){
                    if(newVal[i] && oldVal[i] && newVal[i].item_id==oldVal[i].item_id){
                        newVal[i] = oldVal[i]
                    }
                }
                this.setData({
                  productList:newVal
                })
            }
        },
        showTitle:Boolean,
        bgColor:String,
        is_select:{
            type: [Boolean, String],
            default: false
        },
		is_bigin:{
			type: Boolean,
			value: true
		},
    },
    data: {
        productList: []
    },
    ready() {
        
    },
    methods: {
        //商品详情
        productDetail(e) {
			console.log(e);
            var id = e.currentTarget.dataset.id;
            var p = e.currentTarget.dataset.p;
            var index = e.currentTarget.dataset.index;
            //app.globalData.cur_product = this.data.productList[index];
            app.globalData.cur_product={}
            wx.navigateTo({
                url: '/pages/module/productDetail/productDetail?id=' + id + '&p=' + p,
            })
        },
        chooseProduct(e){
			console.log(e);
            var index = e.currentTarget.dataset.index;
            this.triggerEvent('change', {index: e.currentTarget.dataset.index});
        },
        imgLoad(e){
            var index = e.currentTarget.dataset.index;
            this.data.productList[index].imgShow=true;
            this.setData({
                productList:this.data.productList
            })
        },
        goHot(e){
            var index = e.currentTarget.dataset.index;var index = e.currentTarget.dataset.index;
            this.data.productList[index].is_show_mask=false;
            this.setData({
                productList:this.data.productList
            })
            wx.navigateTo({
              url: '/pages/module/hot/hot?q=' + this.data.productList[index].cid_name,
            })
        },
        showMask(e){
			//console.log(e);
            this.long_click = true;
            var index = e.currentTarget.dataset.index;
            this.data.productList.forEach(item=>{
                item.is_show_mask=false;
            })
            this.data.productList[index].is_show_mask=true;
            this.setData({
                productList:this.data.productList
            })
        },
        hideMask(e){
			console.log(e);
            if(this.long_click){
                this.long_click = false
                return
            } 
            var index = e.currentTarget.dataset.index;
            this.data.productList[index].is_show_mask=false;
            this.setData({
                productList:this.data.productList
            })
        }
    },
})